use binomial_heap::binomial_heap::{BinomialHeap, BinomialHeapType};

#[test]
fn test_binomial_heap_new() {
    let heap = BinomialHeap::<i32>::new(BinomialHeapType::Min);
    assert!(heap.is_some());
    let heap = heap.unwrap();
    assert_eq!(heap.num_values(), 0);
    assert_eq!(heap.roots.len(), 0);
}

#[test]
fn test_binomial_heap_insert() {
    let mut heap = BinomialHeap::new(BinomialHeapType::Min).unwrap();
    assert!(heap.insert(10));
    assert_eq!(heap.num_values(), 1);
    assert!(heap.insert(5));
    assert_eq!(heap.num_values(), 2);
}

#[test]
fn test_binomial_heap_pop() {
    let mut heap = BinomialHeap::new(BinomialHeapType::Min).unwrap();
    heap.insert(10);
    heap.insert(5);
    heap.insert(15);

    assert_eq!(heap.pop(), Some(5));
    assert_eq!(heap.num_values(), 2);
    assert_eq!(heap.pop(), Some(10));
    assert_eq!(heap.num_values(), 1);
    assert_eq!(heap.pop(), Some(15));
    assert_eq!(heap.num_values(), 0);
    assert_eq!(heap.pop(), None);
}

#[test]
fn test_binomial_heap_merge() {
    let mut heap1 = BinomialHeap::new(BinomialHeapType::Min).unwrap();
    heap1.insert(10);
    heap1.insert(5);

    let mut heap2 = BinomialHeap::new(BinomialHeapType::Min).unwrap();
    heap2.insert(15);
    heap2.insert(20);

    assert!(heap1.merge(&mut heap2));
    assert_eq!(heap1.num_values(), 4);
    assert_eq!(heap1.pop(), Some(5));
    assert_eq!(heap1.pop(), Some(10));
    assert_eq!(heap1.pop(), Some(15));
    assert_eq!(heap1.pop(), Some(20));
    assert_eq!(heap1.pop(), None);
}

#[test]
fn test_binomial_tree_merge() {
    let tree1 = Box::new(binomial_heap::binomial_heap::BinomialTree {
        value: 10,
        order: 0,
        subtrees: Vec::new(),
    });

    let tree2 = Box::new(binomial_heap::binomial_heap::BinomialTree {
        value: 5,
        order: 0,
        subtrees: Vec::new(),
    });

    let heap = BinomialHeap::new(BinomialHeapType::Min).unwrap();
    let merged_tree = heap.binomial_tree_merge(tree1, tree2);
    assert!(merged_tree.is_some());
    let merged_tree = merged_tree.unwrap();
    assert_eq!(merged_tree.value, 5);
    assert_eq!(merged_tree.order, 1);
    assert_eq!(merged_tree.subtrees.len(), 1);
}